﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace Group_Project_Book_Store
{
    /// <summary>
    /// Interaction logic for ItemWindow.xaml
    /// </summary>
    public partial class ItemWindow : Window
    {
        private bool EditMode;

        /// <summary>
        /// Constructor to initialize the window
        /// </summary>
        public ItemWindow()
        {
            try
            {
                InitializeComponent();
                EditMode = false;
                txtCode.IsReadOnly = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        /// <summary>
        /// Overloaded constructor for the text fields
        /// </summary>
        /// <param name="code"></param>
        /// <param name="description"></param>
        /// <param name="cost"></param>
        public ItemWindow(string code, string description, string cost)
        {
            try
            {
                InitializeComponent();
                EditMode = true;
                txtCode.IsReadOnly = true; //User cannot edit the def table code
                txtCode.Text = code;
                txtDescription.Text = description;
                txtCost.Text = cost;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        /// <summary>
        /// Updates the new def table description in the database
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (EditMode == true)
                {
                    //DataRepository.UpdateDefinedItem(txtCode.Text, txtDescription.Text, txtCost.Text);
                }
                else
                {
                    //DataRepository.CreateDefinedItem(txtCode.Text, txtDescription.Text, txtCost.Text);
                }

                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        /// <summary>
        /// Exits the Item Window
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

       
    }
}
